package eu.ydp.mathplayer.editor;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.ui.RootPanel;
/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class MathEditorEntryPoint implements EntryPoint {

	private MathEditorManager editor;
	
	public void onModuleLoad() {
		initJavaScriptAPI();
	}

	private native void initJavaScriptAPI() /*-{
		var instance = this;
		
		$wnd.createMathEditor = function(id,source){
			return instance.@eu.ydp.mathplayer.editor.MathEditorEntryPoint::createMathEditor(Ljava/lang/String;Ljava/lang/String;)(id,source);
		}
		
		if(typeof $wnd.mathEditorOnAppLoaded == 'function') {
		  $wnd.mathEditorOnAppLoaded();	
		}
	}-*/;
	
	@SuppressWarnings("unused")
	private JavaScriptObject createMathEditor(String id, String source){
		editor = new MathEditorManager(RootPanel.get(id), source);
		return editor.getJavaScriptObject();
	}
}
